﻿@model Carrotware.CMS.Mvc.UI.Admin.Models.SplitDateTime

@{
	DateTime dtModel = DateTime.MinValue;
	string dateAll = String.Empty;
	string dateDate = String.Empty;
	string dateTime = String.Empty;

	if (Model.CombinedDateTime.HasValue) {
		dtModel = Model.CombinedDateTime.Value;

		dateAll = dtModel.ToString("MM/dd/yyyy hh:mm tt");
		dateDate = dtModel.Date.ToString("MM/dd/yyyy");
		dateTime = dtModel.ToString("hh:mm tt");
	}

	string dateID = String.Format("{0}_Date", Model.FieldName);
	string timeID = String.Format("{0}_Time", Model.FieldName);
}

<script type="text/javascript">
	function SetCombined(fld) {
		var d = $("[name='" + fld + "_Date']").val();
		var t = $("[name='" + fld + "_Time']").val();
		$("[name='" + fld + "']").val(d + ' ' + t);
	}

	$(document).ready(function () {
		$('.dyn-date').each(function () {
			$(this).on('change select textchange blur keyup', function () {
				var v = $(this).attr('dtfld');
				SetCombined(v);
			});
		});
	});
</script>

@Html.Hidden(Model.FieldName, dateAll)

<div style="padding: 0; margin: 0; border: 0; clear: both;">
	<div style="float: left; padding-right: 10px;">
		@Html.TextBox(dateID, dateDate, new { @dtfld = Model.FieldName, maxlength = "12", size = "16", @class = "date-picker dateRegion dyn-date form-control-sm" })
	</div>
	<div style="float: left; padding-right: 10px;">
		@Html.TextBox(timeID, dateTime, new { @dtfld = Model.FieldName, maxlength = "10", size = "16", @class = "time-picker timeRegion dyn-date form-control-sm" })
	</div>
</div>